home *** CD-ROM | disk | FTP | other *** search
- // ConstArrayOf.cp
- #define ConstArrayOf_cp
-
- #ifndef ConstArrayOf_h
- #include "ConstArrayOf.h"
- #endif
- #ifndef MinMax_h
- #include "MinMax.h"
- #endif
-
- template < class Element >
- void ConstArrayOf<Element>::Truncate( uint32 position )
- {
- Assert( !Null() );
- Assert( position <= length )
- length = position;
- }
-
- template < class Element >
- void ConstArrayOf<Element>::Append( ConstArrayType tail )
- {
- Assert( !Null() );
- Assert( Precedes( tail ) );
- length += tail.length;
- }
-
- template < class Element >
- const ConstArrayOf<Element> ConstArrayOf<Element>::operator+( ConstArrayType tail ) const
- {
- ConstArrayType result( *this );
- result += tail;
- return result;
- }
-
- template < class Element >
- void ConstArrayOf<Element>::Prepend( ConstArrayType head )
- {
- Assert( !Null() );
- Assert( Follows( head ) );
- start = head.start;
- length += head.length;
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::operator<=( ConstArrayType r ) const
- {
- return start >= r.start && End() <= r.End();
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::operator<( ConstArrayType r ) const
- {
- return *this <= r && *this != r;
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::IsHeadOf( ConstArrayType r ) const
- {
- return start == r.start && length <= r.length;
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::IsTailOf( ConstArrayType r ) const
- {
- return End() == r.End() && length <= r.length;
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::Touches( ConstArrayType r ) const
- {
- return End() >= r.start && start <= r.End();
- }
-
- template < class Element >
- bool ConstArrayOf<Element>::IsSortedBy( Comparison compare ) const
- {
- for ( uint32 i = 0; i+1 < length; i++ )
- if ( compare( start[i], start[i+1] ) > 0 )
- return false;
- return true;
- }
-
- template < class Element >
- const ConstArrayOf<Element> ConstArrayOf<Element>::operator&( ConstArrayType r ) const
- {
- Assert( !Null() );
- Assert( !r.Null() );
- Assert( Touches( r ) );
- const Element *lastStart = Max( start, r.start );
- const Element *firstEnd = Min( End(), r.End() );
- return ConstArrayType( lastStart, firstEnd - lastStart );
- }
-
- template < class Element >
- const ConstArrayOf<Element> ConstArrayOf<Element>::operator|( ConstArrayType r ) const
- {
- Assert( !Null() );
- Assert( !r.Null() );
- Assert( Touches( r ) );
- const Element *firstStart = Min( start, r.start );
- const Element *lastEnd = Max( End(), r.End() );
- return ConstArrayType( firstStart, lastEnd - firstStart );
- }
-